<?php

namespace app\api\controller;

use app\api\model\ShopGroup;
use app\api\model\ShopOrder;
use app\api\model\ShopProduct;
use app\api\model\ShopCat;
use app\api\model\ShopSlide;
use think\Controller;

class Shop extends Base
{
    //所有商品分类
    public function cats()
    {
        $data = ShopCat::getList();
        return self::apiResp($data);
    }

    //所有商品专题
    public function groups()
    {
        $data = ShopGroup::getList();
        return self::apiResp($data);
    }

    //获取置顶商品列表
    public function pro_top()
    {
        $row = input('row', 10);
        $page = input('page', 1);
        $map['is_top'] = 1;
        $data = ShopProduct::getList($map, $page, $row);
        return self::apiResp($data);
    }

    //根据分类 获取商品列表
    public function pro_search()
    {
        $row = input('row', 10);
        $page = input('page', 1);
        $proName = input('pro_name');
        if($proName=='')
            return self::apiResp(['_code'=>'401','msg'=>'查找内容为空']);
        $map = [];
        $map['pro_name'] = ['LIKE','%'.$proName.'%'];
        $data = ShopProduct::getList($map, $page, $row);
        return self::apiResp($data);
    }

    //根据分类 获取商品列表
    public function pro_cat()
    {
        $row = input('row', 10);
        $page = input('page', 1);
        $catId = input('cat_id');
        $proName = input('pro_name');
        $map = [];
        !empty($catId) && $map['cat_id'] = $catId;
        !empty($proName) && $map['pro_name'] = ['LIKE','%'.$proName.'%'];
        $data = ShopProduct::getList($map, $page, $row);
        return self::apiResp($data);
    }

    //根据专题 获取商品列表
    public function pro_group()
    {
        $row = input('row', 10);
        $page = input('page', 1);
        $groupId = input('group_id');
        $ids = ShopGroup::getProductIds($groupId);
        $map['id'] = ['in', $ids];
        $data = ShopProduct::getList($map, $page, $row);
        return self::apiResp($data);
    }

    //商品详情
    public function product()
    {
        $id = input('id');
        $data = ShopProduct::getById($id);
        return self::apiResp($data);
    }

    //商城轮播
    public function slides()
    {
        $data = ShopSlide::getList();
        return self::apiResp($data);
    }
}
